import { Injectable } from '@angular/core'
import { Observable, Subject } from "rxjs";
import {XYDistance} from '../data_model/data-model'
@Injectable()
export class WindowEventService{
    //window resize通知订阅者
    private WindowResizeSubject = new Subject<any>();
    //在dialog-head区域鼠标按下与否事件
    private DialogMousePressedSubject = new Subject<boolean>();
    //在dialog-head区域鼠标按下之后，鼠标移动事件
    private DialogMouseMovedSubject = new Subject<XYDistance>();


    constructor(){
        window.onresize = (ev)=>{
            this.sendWindowResizeSubject(window);
        }
    
    }
    /////////   send    ////////////////

    sendWindowResizeSubject(ev:Window){
        this.WindowResizeSubject.next(ev);
    }

    sendDialogMousePressedSubject(pressed:boolean){
        this.DialogMousePressedSubject.next(pressed);
    }

    sendDialogMouseMovedSubject(xyInstance:XYDistance){
        this.DialogMouseMovedSubject.next(xyInstance);
    }


    ////////    get     /////////////////////////
    getWindowResizeSubject():Observable<Window>{
        return this.WindowResizeSubject.asObservable();
    }
    getDialogMousePressedSubject():Observable<boolean>{
        return this.DialogMousePressedSubject.asObservable();
    }
    getDialogMouseMovedSubject():Observable<XYDistance>{
        return this.DialogMouseMovedSubject.asObservable();
    }
}